﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;

using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using HRM.HRMServiceProxy;
using HRM.Utilities;

namespace HRM
{
    public partial class frmLaterInsuranceList : DockContent
    {
        BranchClient wcfBranch;
        DepartmentClient wcfDepartment;
        EmployeeClient wcfEmployee;
        LaterInsuranceClient wcfLaterInsurance;
        LaterInsuranceInfo _LaterInsuranceInfo;
        PositionDetailClient wcfPD;
        LeaveWorkClient wcfFM;
        LabourContractClient wcfLC;
        ParameterClient wcfParameter;
        AdvancePaymentClient wcfAdvance;
        int _month = DateTime.Now.Month;
        int _year = DateTime.Now.Year;
        int _LaterInsuranceID;
        int _EmployeeID;
        int _DepartmentID;
        int _BranchID, TagID;
        int _TotalDate;
        decimal _SocialPercent, _MedicalPercent, _BasicSalary;
        decimal _SocialInc, _MedicalInc;
        bool _loadedData = false;  

        decimal _FactorLeave;
        int pageSize = UIParamater.pageSize;
        int currPage = 0;
        int itemCount = 0;
        int totalPage = 0;
        int _CloseBookDay;
        bool _SocialEmployee;
        bool _MedicalEmployee;
        bool _StatusSalary;
        
        RoleRightInfo listRole;
        public frmLaterInsuranceList()
        {
            InitializeComponent();
            Language();
            wcfBranch = Service.Branch();
            wcfDepartment = Service.Department();
            wcfLaterInsurance = Service.LaterInsurance();
            listRole = UIParamater.Quyen_TruyDongBHXH;
            if (!listRole.Update)
            {
                this.btnEdit.Image = Properties.Resources.app;
                this.btnEdit.Tag = "Xem";
            }
           
            UISetting.LoadTreeView3(ref tvBranch);
            Addcolumn();

            UISetting.LoadMonths(ref cboMonth);
            cboMonth.Text = DateTime.Now.Month.ToString();
            UISetting.LoadYears(ref cboYear);
            //cboYear.ComboBox.SelectedValue = Convert.ToUInt32(DateTime.Now.Year);

            LoadData();
            this.KeyPreview = true;
        }

        private void Language()
        {
            if (this.Tag != null)
                this.TabText = UpdateUI.GetString(this.Tag.ToString());
            UpdateUI.Load_ToolStrip(ref toolStrip1);
        }





        private void Addcolumn()
        {
            UISetting.AddColumn(ref dgvList, "LaterInsurance_ID", "Mã chính", "", 1, false, true);
            UISetting.AddColumn(ref dgvList, "RowNumber", UpdateUI.GetString("stt"), "C", 50, true, true);
            UISetting.AddColumn(ref dgvList, "FullName", UpdateUI.GetString("hovaten"), "", 150, true, true);
            UISetting.AddColumn(ref dgvList, "Position_Name", UpdateUI.GetString("chucvu"), "", 100, true, true);
            UISetting.AddColumn(ref dgvList, "LaterInsurance_MonthChange", UpdateUI.GetString("thangtruydong"), "C", 150, true, true);
            UISetting.AddColumn(ref dgvList, "LaterInsurance_BasicFactor", UpdateUI.GetString("hesoluongcoban"), "R", 150, true, true);
            UISetting.AddColumn(ref dgvList, "LaterInsurance_PositionFactor", UpdateUI.GetString("hesophucapchucvu"), "R", 150, true, true);
            UISetting.AddColumn(ref dgvList, "LaterInsurance_OverSeniorityFactor", UpdateUI.GetString("hesothamnienvuotkhung"), "R", 150, true, true);
            UISetting.AddColumn(ref dgvList, "LaterInsurance_SeniorityFactor", UpdateUI.GetString("hesothamnien"), "R", 150, true, true);
            UISetting.AddColumn(ref dgvList, "LaterInsurance_Basic", UpdateUI.GetString("tienluongcoban"), "R", 150, true, true);
            UISetting.AddColumn(ref dgvList, "LaterInsurance_Position", UpdateUI.GetString("phucapchucvu"), "R", 150, true, true);
            UISetting.AddColumn(ref dgvList, "LaterInsurance_OverSeniority", UpdateUI.GetString("phucapthamnienvuotkhung"), "R", 150, true, true);
            UISetting.AddColumn(ref dgvList, "LaterInsurance_Seniority", UpdateUI.GetString("phucapthamnien"), "R", 150, true, true);
            UISetting.AddColumn(ref dgvList, "LaterInsurance_EmployeeSocialIns", UpdateUI.GetString("baohiemxahoinhanvien"), "R", 150, true, true);
            UISetting.AddColumn(ref dgvList, "LaterInsurance_EmployeeMedicalIns", UpdateUI.GetString("baohiemytenhanvien"), "R", 150, true, true);
            UISetting.AddColumn(ref dgvList, "LaterInsurance_SocialIns", UpdateUI.GetString("baohiemxahoicongty"), "R", 150, true, true);
            UISetting.AddColumn(ref dgvList, "LaterInsurance_MedicalIns", UpdateUI.GetString("baohiemytecongty"), "R", 150, true, true);
            UISetting.AddColumn(ref dgvList, "TotalEarn", UpdateUI.GetString("tongtiennhanvienduoclinh"), "R", 150, true, true);
            UISetting.AddColumn(ref dgvList, "LaterInsurance_Date", UpdateUI.GetString("thang"), "C", 80, true, true);
        }

        private void PageIndex()
        {
            totalPage = itemCount % pageSize > 0 ? (itemCount / pageSize) + 1 : (itemCount / pageSize);
            if (totalPage == 0)
                lblPageIndex.Text = "0" + "/" + totalPage.ToString();
            else
                lblPageIndex.Text = (currPage + 1).ToString() + "/" + totalPage.ToString();
        }
        private void LoadData()
        {
            _month = Convert.ToInt32(cboMonth.Text);
            int temptYear;
            if (Int32.TryParse(cboYear.Text, out temptYear))
                _year = temptYear;
            DataSet ds = wcfLaterInsurance.LaterInsurance_GetList(out itemCount, currPage, pageSize, _BranchID, _DepartmentID, _month, _year);
            PageIndex();
            dgvList.Rows.Clear();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                dgvList.Rows.Insert(i, 1);
                dgvList.Columns["RowNumber"].Frozen = true;
                dgvList.Columns["FullName"].Frozen = true;
                dgvList.Columns["Position_Name"].Frozen = true;
                dgvList.Rows[i].Cells["LaterInsurance_ID"].Value = ds.Tables[0].Rows[i]["LaterInsurance_ID"].ToString();
                dgvList.Rows[i].Cells["RowNumber"].Value = ds.Tables[0].Rows[i]["RowNumber"].ToString();
                dgvList.Rows[i].Cells["FullName"].Value = ds.Tables[0].Rows[i]["Employee_LastName"].ToString() + " " + ds.Tables[0].Rows[i]["Employee_FirstName"].ToString();
                dgvList.Rows[i].Cells["Position_Name"].Value = ds.Tables[0].Rows[i]["Position_Name"].ToString();
                dgvList.Rows[i].Cells["LaterInsurance_MonthChange"].Value = Convert.ToDateTime(ds.Tables[0].Rows[i]["LaterInsurance_MonthChange"]).ToString("MM/yyyy");
                dgvList.Rows[i].Cells["LaterInsurance_BasicFactor"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["LaterInsurance_BasicFactor"]).ToString(UIParamater.Cham2So);
                dgvList.Rows[i].Cells["LaterInsurance_PositionFactor"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["LaterInsurance_PositionFactor"]).ToString(UIParamater.Cham2So);
                dgvList.Rows[i].Cells["LaterInsurance_OverSeniorityFactor"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["LaterInsurance_OverSeniorityFactor"]).ToString(UIParamater.Cham2So);
                dgvList.Rows[i].Cells["LaterInsurance_SeniorityFactor"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["LaterInsurance_SeniorityFactor"]).ToString(UIParamater.Cham2So);
                dgvList.Rows[i].Cells["LaterInsurance_Basic"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["LaterInsurance_Basic"]).ToString(UIParamater.Phay2So);
                dgvList.Rows[i].Cells["LaterInsurance_Position"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["LaterInsurance_Position"]).ToString(UIParamater.Phay2So);
                dgvList.Rows[i].Cells["LaterInsurance_OverSeniority"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["LaterInsurance_OverSeniority"]).ToString(UIParamater.Phay2So);
                dgvList.Rows[i].Cells["LaterInsurance_Seniority"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["LaterInsurance_Seniority"]).ToString(UIParamater.Phay2So);
                dgvList.Rows[i].Cells["LaterInsurance_EmployeeSocialIns"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["LaterInsurance_EmployeeSocialIns"]).ToString(UIParamater.Phay2So);
                dgvList.Rows[i].Cells["LaterInsurance_EmployeeMedicalIns"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["LaterInsurance_EmployeeMedicalIns"]).ToString(UIParamater.Phay2So);
                dgvList.Rows[i].Cells["LaterInsurance_SocialIns"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["LaterInsurance_SocialIns"]).ToString(UIParamater.Phay2So);
                dgvList.Rows[i].Cells["LaterInsurance_MedicalIns"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["LaterInsurance_MedicalIns"]).ToString(UIParamater.Phay2So);
                dgvList.Rows[i].Cells["TotalEarn"].Value = Convert.ToDecimal(ds.Tables[0].Rows[i]["TotalEarn"]).ToString(UIParamater.Phay2So);
                dgvList.Rows[i].Cells["LaterInsurance_Date"].Value = Convert.ToDateTime(ds.Tables[0].Rows[i]["LaterInsurance_Date"]).ToString("MM/yyyy");
            }
            _loadedData = true;
        }

        private void btnLaterInsurance_Click(object sender, EventArgs e)
        {
            if (!listRole.Update)
            {
                MessageBox.Show(UpdateUI.GetString("khongcoquyencapnhat"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            _month = Convert.ToInt32(cboMonth.Text);
            int temptYear;
            if (Int32.TryParse(cboYear.Text, out temptYear))
                _year = temptYear;

            //Lấy dữ liệu từ bảng Parameter:

            wcfParameter = Service.Parameter();
            _MedicalPercent = Convert.ToDecimal(wcfParameter.Parameter_GetByName("MedicalInsurancePercentLabour").Value) / 100;
            _SocialPercent = Convert.ToDecimal(wcfParameter.Parameter_GetByName("SocialInsurancePercentLabour").Value) / 100;
            _BasicSalary = Convert.ToDecimal(wcfParameter.Parameter_GetByName("MinBasicSalary").Value);
            _TotalDate = Convert.ToInt32(wcfParameter.Parameter_GetByName("TotalDateWork").Value);
            _SocialInc = Convert.ToDecimal(wcfParameter.Parameter_GetByName("SocialInsurancePercent").Value) / 100;
            _MedicalInc = Convert.ToDecimal(wcfParameter.Parameter_GetByName("MedicalInsurancePercent").Value) / 100;
            _CloseBookDay = Convert.ToInt32(wcfParameter.Parameter_GetByName("CloseBook").Value);
            DateTime _ToDate = DateTime.MinValue;
            _ToDate = UISetting.GetDate(_CloseBookDay + "/" + _month + "/" + _year);

            //Lấy dữ Department theo Branch:
            wcfBranch = Service.Branch();
            wcfDepartment = Service.Department();
            DataTable dtDepart = wcfDepartment.Department_GetAllWithBranch(_BranchID).Tables[0];

            //Lấy dữ liệu từ bảng PositionDetail:
            int _CountMonth;
            int _LaterMonth;
            wcfPD = Service.PositionDetail();
            foreach (DataRow drDepart in dtDepart.Rows)
            {
                _DepartmentID = Convert.ToInt32(drDepart["Department_ID"]);
                //DataTable dtPD = wcfPD.PositionDetail_GetWithDepartment(_DepartmentID).Tables[0];
                DataTable dtEmpl = wcfPD.PositionDetail_GetEmployeeLater(_DepartmentID).Tables[0];
                //foreach (DataRow drPD in dtPD.Rows)
                //{
                foreach (DataRow drEmpl in dtEmpl.Rows)
                {
                    _LaterInsuranceInfo = new LaterInsuranceInfo();
                    _LaterInsuranceInfo.ID = _LaterInsuranceID;
                    _LaterInsuranceInfo.DepartmentID = _DepartmentID;
                    _LaterInsuranceInfo.PositionID = Convert.ToInt32(drEmpl["PD_PositionID"].ToString());
                    _LaterInsuranceInfo.EmployeeID = Convert.ToInt32(drEmpl["PD_EmployeeID"].ToString());
                    _LaterInsuranceInfo.BasicFactor = Convert.ToDecimal(drEmpl["PD_BasicSalaryFactor"].ToString());
                    _LaterInsuranceInfo.PositionFactor = Convert.ToDecimal(drEmpl["PD_PositionFactor"].ToString());
                    _LaterInsuranceInfo.OverSeniorityFactor = Convert.ToDecimal(drEmpl["PD_OverSeniorityFactor"].ToString());
                    _LaterInsuranceInfo.SeniorityFactor = Convert.ToDecimal(drEmpl["PD_SeniorityFactor"].ToString());
                    _LaterInsuranceInfo.CompanyFactor = Convert.ToDecimal(drEmpl["PD_ComSalaryFactor"].ToString());
                    _LaterInsuranceInfo.ResponseFactor = Convert.ToDecimal(drEmpl["PD_ResponsilityFactor"].ToString());

                    _LaterMonth = Convert.ToInt32(Convert.ToDateTime(drEmpl["PD_BeginDate"]).Month);
                    _LaterInsuranceInfo.MonthChange = DateTime.ParseExact(cboMonth.Text + "/" + cboYear.Text, "MM/yyyy", null);
                    _EmployeeID = _LaterInsuranceInfo.EmployeeID;

                    //Lấy dữ liệu từ bảng MarkWork:

                    //wcfMarkWork = Service.MarkWork
                    //DataTable dtMW = wcfMarkWork.MarkWork_GetWithEmployee(_EmployeeID, _month, _year).Tables[0];
                    //foreach (DataRow drMW in dtMW.Rows)
                    //{
                    //    _LaterInsuranceInfo.TotalDateWork = Convert.ToInt32(drMW["TotalDateWork"].ToString());
                    //    if (drMW["TotalOverTime"].ToString().Trim().Length == 0)
                    //        _LaterInsuranceInfo.OverTime = 0;
                    //    else
                    //        _LaterInsuranceInfo.OverTime = Convert.ToDecimal(drMW["TotalOverTime"].ToString());
                    //}

                    //Lấy dữ liệu từ bảng LabourContract:

                    wcfLC = Service.LabourContract();
                    DataTable dtLC = wcfLC.LabourContract_GetWithEmployee(_EmployeeID).Tables[0];
                    foreach (DataRow drLC in dtLC.Rows)
                    {
                        _LaterInsuranceInfo.ProbationFactor = Convert.ToDecimal(drLC["ContractType_Probation"].ToString());
                    }

                    //Lấy dữ liệu từ bảng AdvancePayment;
                    wcfAdvance = Service.AdvancePayment();
                    if (wcfAdvance.AdvancePayment_CheckExistEmployee(_EmployeeID, _month, _year))
                    {

                        _LaterInsuranceInfo.OtherDeduction = wcfAdvance.AdvancePayment_GetInfoEmployee(_EmployeeID).AmountPayment;
                    }

                    //Lấy dữ liệu từ bảng LeaveWork:

                    wcfFM = Service.LeaveWork();
                    if (wcfFM.LeaveWork_CheckExistEmployee(_EmployeeID, _month, _year))
                    {
                        DataTable dt2 = wcfFM.LeaveWork_GetWithEmployee(_EmployeeID, _ToDate).Tables[0];
                        foreach (DataRow dr2 in dt2.Rows)
                        {
                            if (dr2["TotalDateOutWork"].ToString().Trim().Length == 0)
                                _LaterInsuranceInfo.TotalDateOutWork = 0;
                            else if (Convert.ToInt32(dr2["TotalDateOutWork"]) > 26)
                                _LaterInsuranceInfo.TotalDateOutWork = 26;
                            else
                                _LaterInsuranceInfo.TotalDateOutWork = Convert.ToInt32(dr2["TotalDateOutWork"].ToString());

                            if (dr2["TotalDateWorkPaid"].ToString().Trim().Length == 0)
                                _LaterInsuranceInfo.TotalLeavePaid = 0;
                            else if (Convert.ToInt32(dr2["TotalDateWorkPaid"]) > 26)
                                _LaterInsuranceInfo.TotalLeavePaid = 26;
                            else
                                _LaterInsuranceInfo.TotalLeavePaid = Convert.ToInt32(dr2["TotalDateWorkPaid"].ToString());

                            if (dr2["TotalDateWorkUnPaid"].ToString().Trim().Length == 0)
                                _LaterInsuranceInfo.TotalLeaveUnPaid = 0;
                            else if (Convert.ToInt32(dr2["TotalDateWorkUnPaid"]) > 26)
                                _LaterInsuranceInfo.TotalLeavePaid = 26;
                            else
                                _LaterInsuranceInfo.TotalLeaveUnPaid = Convert.ToInt32(dr2["TotalDateWorkUnPaid"].ToString());

                            _FactorLeave = Convert.ToDecimal(dr2["FactorSalary"]);
                            _SocialEmployee = Convert.ToBoolean(dr2["SocialInsurance"]);
                            _MedicalEmployee = Convert.ToBoolean(dr2["MedicalInsurance"]);
                            _StatusSalary = Convert.ToBoolean(dr2["StatusSalary"]);
                        }
                    }
                    else
                    {
                        _LaterInsuranceInfo.TotalDateOutWork = 0;
                        _LaterInsuranceInfo.TotalLeavePaid = 0;
                        _LaterInsuranceInfo.TotalLeaveUnPaid = 0;
                    }

                    _LaterInsuranceInfo = BasicSalary.TruyDong(_LaterInsuranceInfo, _TotalDate, _BasicSalary, _SocialPercent, _MedicalPercent,
                        _SocialInc, _MedicalInc, _SocialEmployee, _MedicalEmployee, _FactorLeave);

                    wcfLaterInsurance = Service.LaterInsurance();
                    wcfEmployee = Service.Employee();

                    _CountMonth = DateDiff(Convert.ToDateTime(drEmpl["PD_BeginDate"]), _LaterInsuranceInfo.MonthChange) + 1;
                    for (int i = 0; i < _CountMonth; i++)
                    {
                        if (_LaterMonth < 10)
                        {
                            _LaterInsuranceInfo.Date = DateTime.ParseExact("0" + _LaterMonth + "/" + cboYear.Text, "MM/yyyy", null).AddMonths(i);
                        }
                        else
                        {
                            _LaterInsuranceInfo.Date = DateTime.ParseExact(_LaterMonth + "/" + cboYear.Text, "MM/yyyy", null).AddMonths(i);
                        }
                        if (wcfLaterInsurance.LaterInsurance_CheckExistEmployee(_EmployeeID, _LaterInsuranceInfo.Date.Month, _year))
                        {//update
                            if (!listRole.Create)
                            {
                                MessageBox.Show(UpdateUI.GetString("khongcoquyenthemmoi"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                return;
                            }
                            if (wcfLaterInsurance.LaterInsurance_Update(_LaterInsuranceInfo))
                            {
                                Program.taskbarNotifier.Show( UpdateUI.GetString("thongbao"), UpdateUI.GetString("capnhatthanhcong"), UIParamater.TIME_MOVE_UP, UIParamater.TIME_SHOW, UIParamater.TIME_MOVE_DOWN);
                                
                            }
                            else
                                MessageBox.Show(UpdateUI.GetString("capnhatkhongthanhcong"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);

                        }
                        else//insert
                        {
                            if (!listRole.Create)
                            {
                                MessageBox.Show(UpdateUI.GetString("khongcoquyenthemmoi"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                return;
                            }
                            _LaterInsuranceInfo.ID = wcfLaterInsurance.LaterInsurance_Insert(_LaterInsuranceInfo);
                            if (_LaterInsuranceInfo.ID > 0)
                            {
                                //Update trạng thái truy đóng:
                                wcfPD.PositionDetail_UpdateEmployeeLater(_EmployeeID, _LaterInsuranceInfo.MonthChange);

                                Program.taskbarNotifier.Show( UpdateUI.GetString("thongbao"), UpdateUI.GetString("capnhatthanhcong"), UIParamater.TIME_MOVE_UP, UIParamater.TIME_SHOW, UIParamater.TIME_MOVE_DOWN);
                               
                            }
                            else
                                MessageBox.Show(UpdateUI.GetString("capnhatkhongthanhcong"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);

                        }
                    }
                }
                //}
            }
        }
        private int DateDiff(DateTime a, DateTime b)
        {
            int _count = 0;
            if (a.Year == b.Year)
                _count = b.Month - a.Month;
            else if (a.Year < b.Year)
                _count = (b.Month - a.Month) + (b.Year - a.Year) * 12;
            return _count;

        }

        private void btnFisrt_Click(object sender, EventArgs e)
        {
            currPage = 0;
            if (TagID == 0)
                LoadData();
            else if (TagID == 1)
                LoadData();
            else if (TagID == 2)
                LoadData();
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            if (totalPage > 0 && currPage < totalPage - 1)
                currPage++;
            if (TagID == 0)
                LoadData();
            else if (TagID == 1)
                LoadData();
            else if (TagID == 2)
                LoadData();
        }

        private void btnPrevious_Click(object sender, EventArgs e)
        {
            if (currPage > 0)
                currPage--;
            if (TagID == 0)
                LoadData();
            else if (TagID == 1)
                LoadData();
            else if (TagID == 2)
                LoadData();
        }

        private void btnLast_Click(object sender, EventArgs e)
        {
            if (totalPage > 0)
                currPage = totalPage - 1;
            if (TagID == 0)
                LoadData();
            else if (TagID == 1)
                LoadData();
            else if (TagID == 2)
                LoadData();
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (dgvList.SelectedRows.Count > 0)
            {
                if (listRole.Update || listRole.View)
                {
                    _LaterInsuranceID = Convert.ToInt32(dgvList.CurrentRow.Cells["LaterInsurance_ID"].Value);
                    Form f = new frmLaterInsuranceInfo(_LaterInsuranceID, listRole);
                    if (f.ShowDialog(this) == DialogResult.OK)
                    {
                        LoadData();
                    }
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void dgvList_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
                btnEdit_Click(null, null);
        }

        private void frmLaterInsuranceList_KeyUp(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Enter:
                    if (!e.Alt && !e.Control)
                    {
                        this.ProcessTabKey(!e.Shift);
                        e.Handled = true;
                    }
                    break;
                case Keys.Escape:
                    this.Dispose();
                    this.Close();
                    break;
                case Keys.F2:
                    btnLaterInsurance_Click(null, null);
                    break;
                case Keys.F3:
                    btnEdit_Click(null, null);
                    break;
            }
        }

        private void tvBranch_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (e.Node.Level == 0)
            {
                _BranchID = 0;
                _DepartmentID = 0;
                LoadData();
                TagID = 0;
            }
            else if (e.Node.Level == 1)
            {
                _BranchID = Convert.ToInt32(e.Node.Tag);
                _DepartmentID = 0;
                currPage = 0;
                LoadData();
                TagID = 1;
            }
            else if (e.Node.Level >= 2)
            {
                _BranchID = 0;
                _DepartmentID = Convert.ToInt32(e.Node.Tag);
                currPage = 0;
                LoadData();
                TagID = 2;
            }
        }

        private void cboMonth_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_loadedData)
            {
                currPage = 0;
                LoadData();
            }
        }

        private void cboYear_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_loadedData)
            {
                currPage = 0;
                LoadData();
            }
        }

        private void frmLaterInsuranceList_Activated(object sender, EventArgs e)
        {
            Language();
            if (dgvList.Columns.Count > 0)
            {
                dgvList.Columns["RowNumber"].HeaderText=UpdateUI.GetString("stt");
                dgvList.Columns["FullName"].HeaderText=UpdateUI.GetString("hovaten");
                dgvList.Columns["Position_Name"].HeaderText=UpdateUI.GetString("chucvu");
                dgvList.Columns["LaterInsurance_MonthChange"].HeaderText=UpdateUI.GetString("thangtruydong");
                dgvList.Columns["LaterInsurance_BasicFactor"].HeaderText=UpdateUI.GetString("hesoluongcoban");
                dgvList.Columns["LaterInsurance_PositionFactor"].HeaderText=UpdateUI.GetString("hesophucapchucvu");
                dgvList.Columns["LaterInsurance_OverSeniorityFactor"].HeaderText=UpdateUI.GetString("hesothamnienvuotkhung");
                dgvList.Columns["LaterInsurance_SeniorityFactor"].HeaderText=UpdateUI.GetString("hesothamniennghe");
                dgvList.Columns["LaterInsurance_Basic"].HeaderText=UpdateUI.GetString("tienluongcoban");
                dgvList.Columns["LaterInsurance_Position"].HeaderText=UpdateUI.GetString("phucapchucvu");
                dgvList.Columns["LaterInsurance_OverSeniority"].HeaderText=UpdateUI.GetString("phucapthamnienvuotkhung");
                dgvList.Columns["LaterInsurance_Seniority"].HeaderText=UpdateUI.GetString("phucapthamniennghe");
                dgvList.Columns["LaterInsurance_EmployeeSocialIns"].HeaderText = UpdateUI.GetString("baohiemxahoinhanvien");
                dgvList.Columns["LaterInsurance_EmployeeMedicalIns"].HeaderText = UpdateUI.GetString("baohiemytenhanvien");
                dgvList.Columns["LaterInsurance_SocialIns"].HeaderText = UpdateUI.GetString("baohiemxahoicongty");
                dgvList.Columns["LaterInsurance_MedicalIns"].HeaderText = UpdateUI.GetString("baohiemytecongty");
                dgvList.Columns["TotalEarn"].HeaderText = UpdateUI.GetString("tongtiennhanvienduoclinh");
                dgvList.Columns["LaterInsurance_Date"].HeaderText = UpdateUI.GetString("thang");
            }
        }

        private void frmLaterInsuranceList_FormClosing(object sender, FormClosingEventArgs e)
        {


        }
    }
}
